This example source release is the cosim demo for the sorting platform.
This release has been tested with the following tools and libs:

Linux 16.04.3
ZeroMQ v4.1.4
CZMQ v4.0.2
Vivado 2017.1
VCS J-2014-12-SP3-8
Verdi I-2014-03-SP2
QEMU 2.10 rc3



Environment variables to set
----------------------------
COSIM_REPO_HOME -> Root of the source release
COSIM_PORT -> Any 4-digit number. If you want to run multiple instances on 
              the same machine, each one needs to have a different number.
NOVAS_HOME -> Verdi home directory. Set it if you want to use FSDB and Verdi.



Compile QEMU
----------------------------
1. Install Dependencies:

    zmq  v4.1.4 -> https://github.com/zeromq/libzmq/releases/download/v4.1.4/zeromq-4.1.4.tar.gz
    czmq v4.0.2 -> https://github.com/zeromq/czmq/releases/download/v4.0.2/czmq-4.0.2.tar.gz
    ncurses

2. Download QEMU 2.10 rc3

    cd $COSIM_REPO_HOME/qemu
    wget http://download.qemu-project.org/qemu-2.10.0-rc3.tar.xz
    tar -xJf qemu-2.10.0-rc3.tar.xz

3. Apply the patch

    patch -s -p0 < qemu-cosim.patch

4. Configure and build

    cd qemu-2.10.0-rc3
    mkdir build
    cd build
    ../configure --target-list=x86_64-softmmu --disable-vnc --enable-sdl --enable-curses

    Modify config-host.mak, Add " -lzmq -lczmq" to the end of LIBS

    make -j32

5. Copy the launch script

    cp ../../../scripts/launch_fpga.sh ./
    cd ../../



Create a QEMU image
----------------------------
Create a QEMU image file called cosim.qcow2 in $COSIM_REPO_HOME/qemu and install Ubuntu 16.04.3.
Install necessary tools for compiling userspace program and kernel module.
Copy $COSIM_REPO_HOME/software_sorting to the image.



Launch QEMU with accelerator
----------------------------
1. Launching QEMU with accelerator

    cd $COSIM_REPO_HOME/qemu/qemu-2.10.0-rc3/build
    ./launch_fpga.sh

2. In the VM, compile and load driver

    cd software_sorting/driver/
    ./loadRunModule.sh

3. In the VM, compile the user space program

    cd ../application
    gcc sort.c -o sort

4. Wait here and use another terminal to launch Vivado and VCS



Launch Vivado and VCS
----------------------------
1. Launch Vivado

    cd $COSIM_REPO_HOME/platform_sim_sorting
    verdi sume_mb_minimal_sim2.xpr

2. Compile simulation library (if haven't done so)
    
    Tools -> Compile Simulation libraries

3. Launch VCS

    SIMULATION -> Run Simulation -> Run Behavioral Simulation

4. Run Simulaton

    In the VCS DVE window, start the simulator



Run the sorting program
----------------------------

1. Back to the QEMU terminal

    sudo ./sort

    The program will first print unsorted data, then print sorted result.



Note for the NIC bridge
----------------------------
The NIC simulation bridge is put in $COSIM_REPO_HOME/ip_sim_bridge/nic_sim_bridge
However, due to some license issues we cannot release the driver and platform at this time.

